struct Player {
    first_name: String,
    last_name: String,
}


impl Player {

    ///静态方法
    fn new(first_name: String, last_name: String) -> Player {
        Player {
            first_name,
            last_name,
        }
    }

    fn full_name(&self) -> String {
        format!("{} {}", self.first_name, self.last_name)
    }
}


struct Person {
    first_name: String,
    last_name: String,
}

trait FullName {
    fn full_name(&self) -> String;
}

trait Employee {
    fn job_title(&self) -> String {
        "Default job title".to_string()
    }
}

trait Male {
    fn interests(&self) -> String {
        "Default interests".to_string()
    }
}

trait MaleEmployee: Employee + Male { // 等效于 impl <T: Empoyee + Male> MaleEmployee for T {}
    fn weight(&self) -> String {
        "Default weight".to_string()
    }
}

// 和继承不一样，rust的trait A: B{} 意味着实现了A的struct必须实现B

impl Employee for Player {}
impl Male for Player {}
impl MaleEmployee for Player{}

impl FullName for Person {
    fn full_name(&self) -> String {
        format!("{} {}", self.first_name, self.last_name)
    }
}

/// 测试不带traits的impl   
pub fn test_impl_without_traits() {
    let player1 = Player {
        first_name: "Rafael".to_string(),
        last_name: "Nadal".to_string()
    };
    println!("Player 01: {}", player1.full_name());
    
}

/// 测试带traits的impl
pub fn test_impl_traits() {
    let player2 = Person {
        first_name: "Roger".to_string(),
        last_name: "Federer".to_string(),
    };

    println!("Player 02: {}", player2.full_name());
}

/// 测试静态方法
pub fn test_impl_static() {
    let player_3 = Player::new("Serena".to_string(), "Williams".to_string());

    println!("Player 03: {}", player_3.full_name());
}

pub fn test_trait_inherit() {
    let player4 = Player {
        first_name: "Juli".to_string(),
        last_name: "Galo".to_string()
    };

    println!("Player 04: {}, {}, {}", player4.full_name(), player4.interests(), player4.weight());
}